package cn.bx.film.ctrl;


import cn.bx.film.entity.FilmInfo;
import cn.bx.film.entity.Page;
import cn.bx.film.service.FilmInfoService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpSession;
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.*;

@Controller
//控制器
public class FilmInfoController {
    //添加日志
    private static final Logger Log = LoggerFactory.getLogger(FilmInfoController.class);

    @Autowired
    //自动装载
    private FilmInfoService filmInfoService;

    @RequestMapping(value = "filminfosearch", produces = "application/json;charset=utf-8")
    @ResponseBody
    public Page<FilmInfo> search(String filmName,String actor,String director) {
        Page<FilmInfo> filmInfos = this.filmInfoService.search(filmName,actor,director);
        return filmInfos;
    }

    @RequestMapping(value = "filminfoadd", produces = "application/json;charset=UTF-8")
    @ResponseBody
    public Object userAdd(@ModelAttribute("f") FilmInfo f) {
        int filminfo = this.filmInfoService.add(f);
        return filminfo;
    }

    @InitBinder
    public void init(WebDataBinder binder) {
        CustomDateEditor dateEditor = new CustomDateEditor(new SimpleDateFormat("yyyy-MM-dd"), true);
        binder.registerCustomEditor(Date.class, dateEditor);
    }
}
